<?php
$prefix = 'class';
if($_POST['action']=='save')
{
	$data = array(
		'commission_1'=>$_POST['commission_1'],
		'commission_2'=>$_POST['commission_2'],
		'commission_3'=>$_POST['commission_3'],
		'commission_4'=>$_POST['commission_4'],
	);	
	if($_POST['id']){
		update("tb_$prefix",$data,"class_id = '".$_POST['id']."'");
		$id = $_POST['id'];
	}else{
		insert("tb_$prefix",$data);	
		$id = mysql_insert_id();	
	}
	$fileupload=$_FILES['fileupload']['tmp_name'];
	$fileupload_name=$_FILES['fileupload']['name'];
	$fileupload_size=$_FILES['fileupload']['size'];
	$fileupload_type=$_FILES['fileupload']['type'];
	
	if ($fileupload) {
			$array_last=explode(".",$fileupload_name);
			$c=count($array_last)-1; 
			$lastname=strtolower($array_last[$c]) ;
			$photoname=date("YmdHis")."_".$id.".".$lastname;
			$image = new SimpleImage();
			$image->load($fileupload);
			
			if($image->getWidth()>700){
				$image->resizeToWidth(700);
			}
			$image->save("../upload/$photoname");
			$data = array(
				"image"=>($photoname),
			);
			update("tb_$prefix",$data,"class_id='".$id."'");											
			unlink($fileupload);
		}
		echo "<script>window.location='admin.php?page=$prefix'</script>";
}
$sql = "select * from tb_$prefix where class_id = '".$_GET['id']."'";
$qr = select($sql);
$rs = $qr[0];
?>
<div id="dialog_active" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการเปลี่ยนสถานะ?</p>
</div>
<div id="dialog2" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการลบข้อมูล?</p>
</div>
<div id="member_dialog" title="ข้อมูลสมาชิก"  style="display:none;"></div>
<div id="tabs">
    <ul>
    	<li><a class="head_tab" style="padding-left:7px;" href="#tabs-1"><span class="ui-icon ui-icon-calendar" style="float:left;"></span>ระดับ <?=$rs['class_name']?></a></li>
    </ul>
    <div id="tabs-1">
    	<form action="" method="post" enctype="multipart/form-data" id="content-form">
          <table width="100%" border="0" cellspacing="0" cellpadding="5">
                  <tr>
                    <td width="15%"><strong>คอมมิสชั่นระดับ 1</strong></td>
                    <td>
                    <input name="commission_1" type="text" id="commission_1" value="<?=$rs['commission_1']?>" size="50" style="width:30px; text-align:center;" /> 
                    %</td>
                <!--</tr>
                  <tr>
                    <td><strong>Image</strong></td>
                    <td>
                    <?php
						if($rs['image']<>''){
							echo "<img src=\"../upload/$rs[image]\" width=100/>";
						}
					?>
                    <input type="file" name="fileupload" id="fileupload" />
                    ขนาดรูปภาพที่แนะนำ 139*139 pixel</td>
                  </tr>-->
                  <tr>
                    <td><strong>คอมมิสชั่นระดับ 2</strong></td>
                    <td><input name="commission_2" type="text" id="commission_2" value="<?=$rs['commission_2']?>" size="50" style="width:30px; text-align:center;" /> 
                      %</td>
                  <tr>
                    <td><strong>คอมมิสชั่นระดับ 3</strong></td>
                    <td><input name="commission_3" type="text" id="commission_3" value="<?=$rs['commission_3']?>" size="50" style="width:30px; text-align:center;" /> 
                      %</td>
                  <tr>
                    <td><strong>คอมมิสชั่นระดับ 4</strong></td>
                    <td><input name="commission_4" type="text" id="commission_4" value="<?=$rs['commission_4']?>" size="50" style="width:30px; text-align:center;" /> 
                      %</td>
                  <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="button" id="button" value="Submit" />
                    <input name="id" type="hidden" id="id" value="<?=$rs['class_id']?>" />
                    <input name="action" type="hidden" id="action" value="save" /></td>
                  </tr>
          </table>
      </form>
    </div>
</div>            